/**
 * 
 */
package com.java.controller.admin;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.java.entity.Good;
import com.java.entity.Order;
import com.java.entity.Payment;
import com.java.service.impl.GoodServiceImpl;
import com.java.service.impl.OrderServiceImpl;
import com.java.service.impl.PaymentServiceImpl;


/**
* @author Kidney
* 创建时间：2019年4月29日 下午3:04:51
* Description:
*/
/**
 * @author KIDNEY
 *
 */
@Controller
@RequestMapping("/order/")
public class OrderController {

	
	@Autowired
	private OrderServiceImpl os;
	
	@Autowired
	private GoodServiceImpl gs;
	
	@Autowired
	private PaymentServiceImpl ps;


	@RequestMapping(value = "all", produces = "application/json; charset=utf-8")
	@ResponseBody
	public String allCourse(Integer paymentId) {

		List<Order> listOrder = os.selectByPayment(paymentId);

		JSONArray array = new JSONArray();

		List<Map<String, Object>> alist = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < listOrder.size(); i++) {
			JSONObject jsonObj = new JSONObject();
			HashMap<String, Object> map = new HashMap<String, Object>();
			
			map.put("orderid", listOrder.get(i).getOrderId());
			
			int goodid =listOrder.get(i).getOrderGood();
			
			Good good = gs.selectByPrimaryKey(goodid);
			
			int paymentid = listOrder.get(i).getPaymentId();
			
			Payment payment = ps.selectByPrimaryKey(paymentid);
			DateFormat df1 = DateFormat.getDateInstance();
			
			
			map.put("goodname", good.getGoodName());
			map.put("username", payment.getName());
			map.put("time",  df1.format(payment.getCreateTime()));
			map.put("express", payment.getExpressNum());
		
			array.add(map);
		}
		return array.toJSONString();
	}



	
}
